///
//  AddbuddyViewController.m
//  chatchatchat
//
//  Created by lanou3g on 16/3/26.
//  Copyright © 2016年 小灰灰. All rights reserved.
//

#import "AddbuddyViewController.h"
#import "additionTableViewCell.h"
#import "SanViewController.h"
#import "LCLoadContactController.h"
#import "PrefixHeader.pch"
#import "radarViewController.h"
@interface AddbuddyViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchResultsUpdating>

@end

@implementation AddbuddyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    self.navigationItem.title = @"添加好友";
    
    //数组赋值
    [self Arrayassignment];
    
    //布局TableView
    [self layoutaTableView];
    
    [self layoutsearchcoller];
    
    //注册cell
    [self.aTableView registerClass:[additionTableViewCell class] forCellReuseIdentifier:@"cell"];
}

- (void)layoutsearchcoller
{
    
    //进行初始化 可以不指控搜索结果控制器
    self.mysearchcoller = [[UISearchController alloc]initWithSearchResultsController:nil];
    
    //搜索结果代理设置
    self.mysearchcoller.searchResultsUpdater = self;
    
    //搜索时是否变暗背景
    self.mysearchcoller.dimsBackgroundDuringPresentation = NO;
    
    //搜索时是否隐藏导航栏
    self.mysearchcoller.hidesBottomBarWhenPushed = NO;
    
    //自适应当前边境大小
    [self.mysearchcoller.searchBar sizeToFit];
    
    self.aTableView.tableHeaderView = self.mysearchcoller.searchBar;

}

//***** 数组赋值 *****//
- (void)Arrayassignment{
    self.aLabelArr = @[@"雷达加好友",@"面对面建群",@"扫一扫",@"手机联系人"];
    self.bLabelArr = @[@"添加身边的朋友",@"与身边的朋友进入同一个群聊",@"扫描二维码名片",@"添加通讯录中的朋友"];
    self.ImageArr = @[@"reda@3x",@"addgroup@3x",@"scanqr@3x",@"contacts@3x"];
}
//***** 布局TableView *****//
- (void)layoutaTableView{
    self.aTableView = [[UITableView alloc]init];
    self.aTableView.frame = CGRectMake(0, KCGFloatheight / 5, KCGFloatwidth,330);
    self.aTableView.scrollEnabled = NO;
    self.aTableView.delegate = self;
    self.aTableView.dataSource = self;
    self.aTableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.aTableView];
}

#pragma mark - TableView 代理

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.aLabelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    additionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"forIndexPath:indexPath];
    
    if (!cell) {
        cell = [[additionTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
    }
    
    //在cell的右边添加 >
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    for (int i = 0; i < indexPath.row + 1; i++)
    {
        cell.aLabel.text = self.aLabelArr[i];
        
        cell.bLabel.text = self.bLabelArr[i];
        
        cell.aImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"add_friend_icon_%@",self.ImageArr[i]]]];
    }
    
    return cell;
}

//***** cell跳转 *****//
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //***** 点击cell取消点击状态 *****//
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    NSInteger index = indexPath.row;
    
    if (index == 0)
    {
        radarViewController *radar = [[radarViewController alloc] init];
        
        [self presentViewController:radar animated:YES completion:nil];
        
    }
    else if (index == 1)
    {
        NSLog(@"面对面建群");
    }
    else if (index == 2)
    {
        SanViewController *sanVC = [[SanViewController alloc] init];
        [self presentViewController:sanVC animated:YES completion:nil];
    }
    else if (index == 3)
    {
        LCLoadContactController *LCVC = [[LCLoadContactController alloc] init];
        
        [self.navigationController pushViewController:LCVC animated:YES];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
